package com.ruoyi.canteen.controller.v1;

import com.ruoyi.canteen.domain.CanteenNotice;
import com.ruoyi.canteen.service.ICanteenNoticeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Ryan
 * @Date 2021/10/8 16:51
 * @Version 1.0
 */
@RestController
@RequestMapping("/v1/notice")
public class NoticeApiController extends BaseController {

    @Autowired
    private ICanteenNoticeService canteenNoticeService;

    /**
     * 查询未指定食堂（所有食堂）
     * 最新一条公告
     * @return
     */
    @GetMapping(value = "/getLastOne")
    public AjaxResult getLastOne()
    {
        return AjaxResult.success(canteenNoticeService.selectCanteenNoticeLastOne(null));
    }

    /**
     * 查询指定食堂
     * 最新一条公告
     * @return
     */
    @GetMapping(value = "/getLastOneByMdId/{id}")
    public AjaxResult getLastOneByMdId(@PathVariable("id") Long id)
    {
        CanteenNotice canteenNotice = new CanteenNotice();
        canteenNotice.setMdId(id);
        canteenNotice.setDeleteTime(null);
        canteenNotice.setIsDefalut(Long.valueOf(1));
        List<CanteenNotice> list = canteenNoticeService.selectCanteenNoticeList(canteenNotice);
        if(list.size() > 0){
            return AjaxResult.success(list.get(0));
        }
        return AjaxResult.success(null);
    }


}
